package com.restaurant.application.util;

import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.MessageFormat;
import java.util.Map;

public class BoxPhoneCodeUtils {
    private static Logger logger = LoggerFactory.getLogger(BoxPhoneCodeUtils.class);
    private static String MSG = "【宝管家】您的验证码是{0}";
    private final static String apikey = "e3b85e51931ee010f0465cb9ac3adc70";
    private final static String KEEPTIME = "10分钟";

    public static void sendVerificationCode(String phoneNumber, String code) {
        logger.debug("phoneNumber:{},code:{},at time:{}", phoneNumber, code, CommonUtils.getDate());
        YunpianClient client = new YunpianClient(apikey).init();
        Map<String, String> param = client.newParam(2);
        param.put(YunpianClient.MOBILE, phoneNumber);
        param.put(YunpianClient.TEXT, MessageFormat.format(MSG, code));
        Result<SmsSingleSend> result = client.sms().single_send(param);
        logger.debug("yun pian result code {},result detail {},result msg {}", result.getCode(), result.getDetail(), result.getMsg());
        client.close();
    }

    public static void sendSharetoFriend(String phoneNumber, String url, String userName) {
        YunpianClient client = new YunpianClient(apikey).init();
        Map<String, String> param = client.newParam(2);
        param.put(YunpianClient.MOBILE, phoneNumber);
        param.put(YunpianClient.TEXT, "【bling囤宝】您的朋友‘" + userName + "’邀请您加入囤宝，现在点击链接" + url + "即可获得·····");
        Result<SmsSingleSend> result = client.sms().single_send(param);
        System.out.println(result.getCode() + "***" + result.getDetail());
        client.close();
    }

}
